--Creating a table to store server health
--statistics data if the table does not exist.
IF OBJECT_ID('[dbo].[tbl_ServerHealthStatistics]') IS NULL
BEGIN
CREATE TABLE [dbo].[tbl_ServerHealthStatistics]
(
ID INT IDENTITY(1,1)
,StatDateTime DATETIME DEFAULT GETDATE()
,TotalConnections INT
,TimeTicks INT
,TotalCPUBusyTime INT
,TotalCPUIdleTime INT
,TotalIOBusyTime INT
,TotalReceivedPackets INT
,TotalSentPackets INT
,TotalErrorsInNetworkPackets INT
,TotalPhysicalReadOperations INT
,TotalWriteOperations INT
,TotalReadWriteErrors INT
)
END
GO
--Collect and store server health statistics
--data in our table.
INSERT INTO [dbo].[tbl_ServerHealthStatistics]
(
TotalConnections
,TimeTicks
,TotalCPUBusyTime
,TotalCPUIdleTime
,TotalIOBusyTime
,TotalReceivedPackets
,TotalSentPackets
,TotalErrorsInNetworkPackets
,TotalPhysicalReadOperations
,TotalWriteOperations
,TotalReadWriteErrors
)
SELECT
@@CONNECTIONS AS TotalConnections
,@@TIMETICKS AS TimeTicks
,@@CPU_BUSY AS TotalCPUBusyTime
,@@IDLE AS TotalCPUIdleTime
,@@IO_BUSY AS TotalIOBusyTime
,@@PACK_RECEIVED AS TotalReceivedPackets
,@@PACK_SENT AS TotalSentPackets
,@@PACKET_ERRORS AS TotalErrorsInNetworkPackets
,@@TOTAL_READ AS TotalPhysicalReadOperations
,@@TOTAL_WRITE AS TotalWriteOperations
,@@TOTAL_ERRORS AS TotalReadWriteErrors
GO
select * from tbl_ServerHealthStatistics
select @@TIMETICKS

sp_monitor
sp_who 'active'
dbcc sqlperf(logspace)